<template>
  <!-- 报销申请-->
  <div class="ReimbursementApply">
    <div class="side_1"></div>
    <span class="add_1">报销申请</span>
    <el-button type="info" icon="el-icon-back" class="btn_fanhui" @click="Fh">返回</el-button>

    <div class="body">
      <div class="div_title">
        <span>报销申请</span>
      </div>
      <el-table show-header :data="tableData" border height="309" show-overflow-tooltip>
        <el-table-column prop label="发生日期" width="180" align="center">
          <template slot-scope="scope">
            <el-date-picker
              type="date"
              placeholder="yyyy-MM-dd"
              v-model="scope.row.date"
              style="width:90%"
            ></el-date-picker>
          </template>
        </el-table-column>
        <el-table-column prop label="报销内容" align="center">
          <template slot-scope="scope">
            <el-input placeholder="报销内容" v-model="scope.row.main"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop label="单据数量" align="center" width="130">
          <template slot-scope="scope">
            <el-input
              placeholder="0"
              v-model="scope.row.billNum"
              oninput="value=value.replace(/[^\d]/g,'')"
            ></el-input>
          </template>
        </el-table-column>
        <el-table-column prop label="金额（元）" align="center" width="130">
          <template slot-scope="scope">
            <el-input
              placeholder="0.00"
              v-model="scope.row.price"
              oninput="value=value.match(/^\d*(\.?\d{0,2})/g,'')"
              @blur="jisuan(scope)"
            ></el-input>
          </template>
        </el-table-column>
        <el-table-column prop label="备注" align="center">
          <template slot-scope="scope">
            <el-input placeholder="备注" v-model="scope.row.note"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <table style="text-align: center;">
        <tr>
          <td style="width:180px;text-align:center;">合计（元）</td>
          <td>
            <el-input class="elipt" :disabled="true" v-model="total"></el-input>元
          </td>
        </tr>
      </table>
    </div>
    <div class="btn_bottom">
      <el-button type="primary" size="medium" @click="queD">确定</el-button>
      <el-button type="info" size="medium" @click="Fh">返回</el-button>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  computed: {},
  data () {
    return {
      aaa: "primary",
      bbb: "info",
      creater: 0,
      total: 0,
      daxie: '',
      tableData: [{ date: "", main: "", billNum: "", price: "", note: "" }, { date: "", main: "", billNum: "", price: "", note: "" }, { date: "", main: "", billNum: "", price: "", note: "" }, { date: "", main: "", billNum: "", price: "", note: "" }],
      Mark: 0,
    }
  },
  created () {
    this.creater = JSON.parse(localStorage.getItem("message")).Id;
  },

  methods: {

    Fh () {
      window.history.go(-1);
    },
    //合计
    jisuan (e) {
      console.log(e.row.price)
      let sum = 0.00;
      for (var i = 0; i < this.tableData.length; i++) {
        if (this.tableData[i].price != "") {
          console.log(parseFloat(this.tableData[i].price))
          sum += parseFloat(this.tableData[i].price);
        }
      }
      this.total = sum;
    },
    // 确定即保存
    queD () {
      if (this.Mark == 0) {
        if (this.total == 0 || this.total == "") { this.$message.error("金额非空"); return; }
        var det = this.tableData;
        var obj = { basemess: { priceToatl: this.total, creater: this.creater }, det: det }
        var objs = JSON.stringify(obj); let the = { index: 4, jsondata: objs }
        this.Mark=1;
        axios.post("/apis/MyCenter.asmx/Add", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          console.log(list);
          if (list.flag == true) {
            this.$message.success(list.tip);
            setTimeout(() => {
              window.history.go(-1);
            }, 500);
          } else {
            this.$message.error(list.tip);
          }
        })
      }
    },

  }
};
</script>

<style lang="scss" scoped>
@import '@/assets/scss/base.scss';
.body {
  width: 98%;
  margin-top: 40px;
  margin-left: 20px;
  overflow: hidden;
  background-color: $white;
}
.side_1 {
  width: 5px;
  height: 16px;
  background-color: $Header_color;
  margin-left: 10px;
  margin-top: 30px;
}
.add_1 {
  margin-left: 20px;
  margin-top: -20px;
  float: left;
  font-size: 18px;
  font-weight: 400;
}
.btn_fanhui {
  margin-top: -20px;
  margin-right: 20px;
  float: right;
}
.div_title {
  text-align: center;
  margin: 0 auto;
  margin-top: 80px;
  color: #333;
  font-size: 16px;
  font-weight: 700;
  width: calc(80% - 2px);
  border: 1px solid rgb(238, 232, 232);
  border-bottom: none;
  height: 80px;
  line-height: 80px;
}
.el-table {
  width: 80%;
  margin: 0 auto;
}
.btn_bottom {
  margin-top: 30px;
  margin: 30px auto;
  text-align: center;
}
table,
tr {
  height: 60px;
}
table tr td {
  border: 1px solid #e7e7e7;
  border-top: 0.5px;
}
table {
  width: 80%;
  margin: 0 auto;
  margin-bottom: 80px;
}

.elipt {
  width: 50%;
  margin: 0 auto;
  margin-right: 5px;
}
</style>
